﻿Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System.Drawing

Public Class frmSistema
    'Deshabilitar boton [X]
    Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer
    Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    Public Const SC_CLOSE = &HF060&
    Public Const MF_BYCOMMAND = &H0&
    Function RemoveXButton(ByVal iHWND As Integer) As Integer
        Dim iSysMenu As Integer
        iSysMenu = GetSystemMenu(iHWND, False)
        Return RemoveMenu(iSysMenu, SC_CLOSE, MF_BYCOMMAND)
    End Function

    Private Sub frmSistema_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Application.Exit()
    End Sub

    Private Sub frmSistema_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'Salir con [X]
    End Sub

    Private Sub frmSistema_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Deshabilitar boton [X]
        RemoveXButton(Me.Handle().ToInt32())

        'Validacion de visualizacion de modulos por Nivel de Usuario
        ' 1 = Administrador (todos menos modulo Gestion)
        ' 2 = Tecnico de Laboratorio (todo menos modulo Administracion)



        Dim opc As Integer = cU.tipLogueado

        Select Case (opc)
            Case 1
                'MsgBox("Administrador: " + CStr(cU.codigoUsuarioTipo) + " | " + CStr(cU.tipLogueado))
                mGestion.Visible = False
            Case 2
                'MsgBox("Tecnico de Laboratorio: " + CStr(cU.codigoUsuarioTipo) + " | " + CStr(cU.tipLogueado))
                mAdministracion.Visible = False
            Case Else
                Me.Hide()
                'Inicio
                Dim inicio As New frmInicio
                inicio.Show()
        End Select

        ToolStripStatusLabel1.Text = UCase(cU.tusLogueado) + " » " + cU.usuLogueado
        ToolStripStatusLabel2.Text = " | SESION » " + Now()
    End Sub

    Private Sub menustrip_cerrarSesion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mArchivo_cerrarSesion.Click
        Me.Hide()
        frmtest = False
        'Inicio
        Dim inicio As New frmInicio
        inicio.Show()
    End Sub

    Private Sub menustrip_salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mArchivo_salir.Click
        'Salir con menu (Archivo > Salir)
        Dim msgSalir = MsgBox("¿Realmente desea salir?", MsgBoxStyle.YesNo Or MsgBoxStyle.Exclamation)
        If msgSalir = MsgBoxResult.Yes Then
            Me.Close()
        End If
    End Sub

    Private Sub menustrip_perfil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mArchivo_perfil.Click
        If frmprofile = False Then
            frmprofile = True
            'mArchivo
            Dim perfil As New frmPerfil
            perfil.MdiParent = Me
            perfil.Show()
        End If
    End Sub

    Private Sub menustrip_paciente_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mGestion_paciente.Click
        If frmpatient = False Then
            frmpatient = True
            'mGestion
            Dim paciente As New frmPaciente
            paciente.MdiParent = Me
            paciente.Show()
        End If
    End Sub

    Private Sub menustrip_inventario_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If frminventory = False Then
            frminventory = True
            'mGestion
            Dim inventario As New frmInventario
            inventario.MdiParent = Me
            inventario.Show()
        End If
    End Sub

    Private Sub menustrip_personal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAyuda_usuario.Click
        If frmuser = False Then
            frmuser = True
            'mAdministracion
            Dim usuario As New frmUsuario
            usuario.MdiParent = Me
            usuario.Show()
        End If
    End Sub

    Private Sub menustrip_contactar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAyuda_contactarDesarrollador.Click
        If frmcontact = False Then
            frmcontact = True
            'mAyuda
            Dim contactar As New frmContactarDesarrolladores
            contactar.MdiParent = Me
            contactar.Show()
        End If
    End Sub

    Private Sub menustrip_desarrollador_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAyuda_informacionDesarrollador.Click
        If frminformation = False Then
            frminformation = True
            'mAyuda
            Dim informacion As New frmInformacionDesarrolladores
            informacion.MdiParent = Me
            informacion.Show()
        End If
    End Sub

    Private Sub menustrip_ilab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAyuda_acercaIlab.Click
        If frmabout = False Then
            frmabout = True
            'mAyuda
            Dim acerca As New frmAcercaIlab
            acerca.MdiParent = Me
            acerca.Show()
        End If
    End Sub

    Private Sub GestionarReporteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mReporte_reporte.Click
        If frmreport = False Then
            frmreport = True
            'mReporte
            Dim reporte As New frmGestionReporte
            reporte.MdiParent = Me
            reporte.Show()
        End If
    End Sub

    Private Sub tsb_cerrarTodo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Declaramos una variable integer para 
        'contar las ventanas abiertas.
        Dim k As Integer

        'Creamos un ciclo para buscar el Form que tenga el Foco
        For k = 1 To Application.OpenForms.Count - 1
            'Si el Form X tiene el Foco
            If Application.OpenForms.Item(k).Focused Then
                'Cerramos el Form que tiene el Foco
                Application.OpenForms.Item(k).Close()
            End If
        Next
    End Sub

    Private Sub GestionarInventarioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mGestion_Inventario.Click
        If frminventory = False Then
            frminventory = True
            'mGestion
            Dim inventario As New frmInventario
            inventario.MdiParent = Me
            inventario.Show()
        End If
    End Sub

    Private Sub mGestion_examen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mGestion_examen.Click
        If frmtest = False Then
            frmtest = True
            'mGestion
            'Dim examen As New frmGestionarExamen
            'If examen.Visible = False Then
            examen.MdiParent = Me
            examen.Show()
            'examen.BringToFront()
            'examen.Visible = True
            'End If
        End If
    End Sub

    Private Sub mAyuda_manualUsuario_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAyuda_manualUsuario.Click
        If frmmanual = False Then
            frmmanual = True
            'mAyuda
            Dim manual As New frmManualUsuario
            manual.MdiParent = Me
            manual.Show()
        End If
    End Sub

   

End Class